package com.gali.juc;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: gali
 * @Date: 2022-08-22 17:44
 * @Description:
 */
public class VolatileSeeDemo {
//    static boolean flag = true;
      static volatile boolean flag = true;
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"\t come in ");
            while (flag){

            }
            System.out.println(Thread.currentThread().getName()+"\t flag为false");
        },"a").start();
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        flag=false;
        System.out.println(Thread.currentThread().getName()+"\t main 修改完成");
    }
}
